<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>canvas</title>
    <style>
    #canvas{
        display: block;
        margin: 0 auto;
        border: 1px solid #eee;
    }
    </style>
</head>
<body>
    <canvas id="canvas" width="400" height="300"></canvas>
    <script>
        /** @type {HTMLCanvasElement} */
        let canvas = document.querySelector('#canvas');
        let ctx = canvas.getContext('2d');
        let w = ctx.canvas.width;
        let h = ctx.canvas.height;
        let space = 20;
        let arrowSize = 5;
        // 绘制x轴
        ctx.beginPath();
        ctx.moveTo(space,h-space);
        ctx.lineTo(w-space,h-space)
        ctx.strokeStyle = 'red' // 线条颜色
        ctx.stroke()
        // 绘制x轴箭头
        ctx.lineTo(w-space-arrowSize,h-space-arrowSize)
        ctx.lineTo(w-space-arrowSize,h-space+arrowSize)
        ctx.lineTo(w-space,h-space)
        ctx.fillStyle = 'red'
        ctx.fill()
        // 绘制y轴
        ctx.beginPath()
        ctx.moveTo(space,h-space);
        ctx.lineTo(space,space)
        ctx.stroke()
        // 绘制Y轴箭头
        ctx.lineTo(space-arrowSize,space+arrowSize)
        ctx.lineTo(space+arrowSize,space+arrowSize)
        ctx.lineTo(space,space)
        ctx.fillStyle = 'red'
        ctx.fill()
        
    </script>
</body>
</html>